<template>
  <div class="container" @click="handleGalleryClick">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(item, index) in imgs" :key="index">
          <!-- <img class="gallery-img" :src="item"> -->
          <div class="gallery-img" :style="{'background':'url('+item+')','background-position':'center','background-repeat':'no-repeat','background-size':'contain'}"></div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'CommonGallery',
  props: {
    imgs: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {
      // 如果使用v-show去显示轮播图会出现无法滚动的bug，解决方法如下：当轮播图和他的父元素更新数据时就会重新渲染轮播图
      swiperOption: {
        pagination: '.swiper-pagination',
        paginationType: 'fraction',
        observeParents: true,
        observer: true
      }
    }
  },
  methods: {
    handleGalleryClick () {
      this.$emit('close')
    }
  }
}
</script>

<style lang="stylus" scoped>
  .container >>> .swiper-container
    // overflow inherit
    width 100%
    height 100%
  .container
    display flex
    flex-direction column
    justify-content center
    z-index 99
    position fixed
    top 0
    right 0
    bottom 0
    left 0
    background #000
    .gallery-img
      width 100%
      height 100%
    .swiper-pagination
      color #fff
      bottom 1rem
</style>
